//
//  DetailTopicCell.m
//  NeteaseNewsLY
//
//  Created by dllo on 16/1/23.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DetailTopicCell.h"

@implementation DetailTopicCell
- (void)dealloc
{
    [_bigPic release];
    [_userHeadPicUrl release];
    [_userName release];
    [_content release];
    [_slinelabel release];
    [_specialistHeadPicUrl release];
    [_specialistName release];
    [_xlinelabel release];
    [_answercontent release];
    [_supportCount release];
    [_zan release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.userHeadPicUrl = [[UIImageView alloc] init];
        [self.contentView addSubview:_userHeadPicUrl];
        _userHeadPicUrl.layer.cornerRadius = 15;
        _userHeadPicUrl.clipsToBounds = YES;
        [_userHeadPicUrl release];
        
        self.userName = [[UILabel alloc] init];
        [self.contentView addSubview:_userName];
        _userName.font = [UIFont systemFontOfSize:12];
        _userName.textColor = [UIColor grayColor];
        [_userName release];
        
        self.content = [[UILabel alloc] init];
        [self.contentView addSubview:_content];
        [_content release];
        _content.numberOfLines = 0;

        
        self.slinelabel = [[UILabel alloc] init];
        [self.contentView addSubview:_slinelabel];
        // 灰色透明
        _slinelabel.backgroundColor = [UIColor grayColor];
        _slinelabel.alpha = 0.1;
        [_slinelabel release];
        
        self.specialistHeadPicUrl = [[UIImageView alloc] init];
        [self.contentView addSubview:_specialistHeadPicUrl];
        _specialistHeadPicUrl.layer.cornerRadius = 15;
        _specialistHeadPicUrl.clipsToBounds = YES;
        [_specialistHeadPicUrl release];
        
        self.specialistName = [[UILabel alloc] init];
        [self.contentView addSubview:_specialistName];
        _specialistName.font = [UIFont systemFontOfSize:12];
        _specialistName.textColor = [UIColor grayColor];
        [_specialistName release];
        
        self.answercontent = [[UILabel alloc] init];
        [self.contentView addSubview:_answercontent];
        [_answercontent release];
        _answercontent.numberOfLines = 0;
        
        self.xlinelabel = [[UILabel alloc] init];
        [self.contentView addSubview:_xlinelabel];
        _xlinelabel.backgroundColor = [UIColor grayColor];
        _xlinelabel.alpha = 0.1;
        [_xlinelabel release];
        
        self.supportCount = [[UILabel alloc] init];
        [self.contentView addSubview:_supportCount];
        [_supportCount release];
        
        
        self.zan = [[UILabel alloc] init];
        [self.contentView addSubview:_zan];
        _zan.text = @"good";
        _zan.textColor = [UIColor grayColor];
        _zan.font = [UIFont systemFontOfSize:12];
        [_zan release];
    }          
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
//    _bigPic.frame = CGRectMake(5, 10, 365, 300);
    
    _userHeadPicUrl.frame = CGRectMake(WIDTH * 20, HEIGHT * 10, WIDTH * 30, HEIGHT * 30);
    
    _userName.frame = CGRectMake(WIDTH * 55, HEIGHT * 10, WIDTH * 300, HEIGHT * 25);

    CGFloat h = [[self class] heightWithQuestion:_content.text];
    _content.frame = CGRectMake(WIDTH * 40, HEIGHT * 40, self.contentView.bounds.size.width - WIDTH * 50, HEIGHT * h);
//    _content.frame = CGRectMake(40, 40, 325, 50);
    
    _slinelabel.frame = CGRectMake(WIDTH * 20, HEIGHT * (60 + h), WIDTH * 335, HEIGHT * 1);
    
    _specialistHeadPicUrl.frame = CGRectMake( WIDTH * 20, HEIGHT * (70 + h), WIDTH * 30, HEIGHT * 30);
    
    _specialistName.frame = CGRectMake(WIDTH * 55, HEIGHT * (70 + h), WIDTH * 100, HEIGHT * 25);
      
//    _answercontent.frame = CGRectMake(40, 140, 325, 50);
   
    CGFloat ansH = [[self class]heightWithQuestion:_answercontent.text];
    _answercontent.frame = CGRectMake(WIDTH * 40, HEIGHT * (115 + h), self.contentView.bounds.size.width - WIDTH * 50, HEIGHT * ansH);
    
    _xlinelabel.frame = CGRectMake(WIDTH * 20, HEIGHT * (125 + h + ansH), WIDTH * 335, HEIGHT * 1);
    
    _zan.frame = CGRectMake(WIDTH * 245, HEIGHT * (155 + h + ansH), WIDTH * 40,HEIGHT * 20);
    
    _supportCount.frame = CGRectMake(WIDTH * 290, HEIGHT * (155 + h + ansH), WIDTH * 50, HEIGHT * 20);
    _supportCount.font = [UIFont systemFontOfSize:12];
    _supportCount.textColor = [UIColor grayColor];

    
    
}
// 高度
+ (CGFloat)heightWithQuestion:(NSString *)text
{
    // 保存文本属性
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:17]};
    // 预设尺寸
    CGSize size = CGSizeMake(WIDTH * (375 - 50), HEIGHT * 1000);
    // 根据文本 计算出一个cgrect
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    // 返回得到的高度
    return rect.size.height;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
